<?php


namespace App\Logic;


use Illuminate\Http\Request;

class liveBroadcastLogic
{
    /**
     * 获取推流地址
     * 如果不传key和过期时间，将返回不含防盗链的url
     * @param domain 您用来推流的域名
     *        streamName 您用来区别不同推流地址的唯一流名称
     *        key 安全密钥
     *        time 过期时间 sample 2016-11-12 12:00:00
     * @return String url
     */
    private $plugFlow=[
        'key_name_bo'=>'bo.wangjinyu.cloud.txlivecdn.com',//播流地址
        'key_name_push'=>'182305.push.tlivecloud.com',//推流地址
        'key_secure'=>'6568a8af7ddb487c9f3c61e10b1f7cff'//加密安全
    ];

    function getPushUrl($domain,$streamName){
        $key_secure=$this->plugFlow['key_secure'];
        $time=time()+(60*60*24);
        if($key_secure && $time){
            $txTime = strtoupper(base_convert($time,10,16));
            //txSecret = MD5( KEY + streamName + txTime )
            $txSecret = md5($key_secure.$streamName.$txTime);
            $ext_str = "?".http_build_query(array(
                    "txSecret"=> $txSecret,
                    "txTime"=> $txTime
                ));
        }
        return "webrtc://".'182305.push.tlivecloud.com'.'/'.$domain.'/'.$streamName . (isset($ext_str) ? $ext_str : "");
    }
    /**
     * @param $domain
     * @param $streamName
     * @return string
     * 播流
     */
    function getBoUrl($domain, $streamName){
        return "rtmp://".'bo.wangjinyu.cloud/'.$domain.'/'.$streamName;
    }
}
